﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace HandyControlPractice
{
    public class TreeNodeViewModel : NotifyPropertyChangedBaseClass
    {
        public ObservableCollection<TreeNode> TreeNodes { get; set; }

        public TreeNodeViewModel()
        {
            TreeNodes = new ObservableCollection<TreeNode>
            {
                new TreeNode { Name = "Parent 1", Children = new ObservableCollection<TreeNode> { new TreeNode { Name = "Child 1" }, new TreeNode { Name = "Child 2" } } },
                new TreeNode { Name = "Parent 2", Children = new ObservableCollection<TreeNode> { new TreeNode { Name = "Child 3" }, new TreeNode { Name = "Child 4" } } }
            };
        }

    }
    public class NotifyPropertyChangedBaseClass : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string propertyname = "")//通过该方法可以直接获取调用者的名称 前提是需要有默认参数
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
        }
    }
}
